<template>
  <Form
    ref="contentForm"
    :model="form"
    :rules="rules"
    @keydown.enter.native="handleSubmit"
    inline
    :label-width="80"
    >
    <FormItem prop="title" style="width: 250px" label="关键字：">
      <Input type="text" v-model="form.title" placeholder="请输入关键字"/>
    </FormItem>
    <FormItem prop="ctime" style="width: 250px" label="创建日期：">
      <DatePicker v-model="form.ctime" type="date" placeholder="请选择创建日期"></DatePicker>
    </FormItem>
    <FormItem style="float: right;">
      <Button @click="handleSubmit" icon="md-search" type="primary">
        搜索
      </Button>
    </FormItem>
  </Form>
</template>
<script>
import {
  mapState,
  mapActions,
  mapMutations
} from 'vuex'
export default {
  name: 'ContentForm',
  props: {
    ctimeRules: {
      type: Array,
      default: () => {
        return []
      }
    },
    titleRules: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      form: {
        ctime: '',
        title: ''
      }
    }
  },
  computed: {
    rules () {
      return {
        ctime: this.ctimeRules,
        title: this.titleRules
      }
    }
  },
  methods: {
    handleSubmit () {
      this.$refs.contentForm.validate((valid) => {
        if (valid) {
          this.$emit('on-success-valid', {
            ctime: this.form.ctime ? this.$moment(this.form.ctime).format('YYYY-MM-DD HH:mm:ss') : '',
            title: this.form.title
          })
        }
      })
    }
  }
}
</script>
